import React, { useEffect, useState } from "react";
import {Row,Col} from 'antd';
import Add from "../../components/student/antd/Add";
import Update from "../../components/student/antd/Update";
import List from "../../components/student/antd/List";
import Search from "../../components/student/antd/SearchElement";
import { getAll } from "../../services/student";
export default function Student() {
    let [students, setStudents] = useState([]);
    let [pagination, setPagination] = useState({
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: (total) => `总共 ${total} 条`,
        pageSizeOptions: [5, 10, 15, 20],
    });
    let [searchObj, setSearchObj] = useState({});
    const show = async (params) => {
        if (params) {
            if(!params.current){
                params.current = 1;
                params.pageSize = pagination.pageSize;
            }
            params = {...searchObj,...params}
            setSearchObj(params);
        } else {
            params = searchObj;
        }
        let data = await getAll(params);
        setStudents(data.data.rows);
        setPagination({
            ...pagination,
            total: data.data.total,
            pageSize: data.data.pageSize,
        });
    };
    useEffect(() => {
        show();
    }, [students.length]);
    return (
        <>
            <Row>
                <Col span={1}>
                    <Add show={show}></Add>
                </Col>
                <Col span={12}>
                    <Search show={show}></Search>
                </Col>
            
            </Row>
            <Update
                show={show}
            ></Update>
            <List
                show={show}
                students={students}
                pagination={pagination}
            ></List>
        </>
    );
}
